package com.itcs.box.server.resolver;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.itcs.box.domain.BoxRequest;
import com.itcs.box.util.LogUtils;
import com.itcs.dubbo.service.DubboService;

import io.netty.channel.ChannelHandlerContext;

/**
 * 发送车道交易完成结果
 * 
 * @author LiuPeng
 * @date 2017年12月12日
 * 
 */
@Component
public class Box1009Resolver implements MsgResolverAdapter {

	private Log logger = LogFactory.getLog(getClass());

	private ExecutorService executorService = Executors.newFixedThreadPool(10);

	@Resource(name = "itcsApp")
	private DubboService itcsApp;

	@Override
	public boolean support(BoxRequest boxRequest) {
		return "1009".equals(boxRequest.getMessgeType());
	}

	@Override
	public void resolve(ChannelHandlerContext channelHandlerContext, BoxRequest boxRequest) {

		logger.info(LogUtils.build("1009", "车道交易完成结果",
				"通讯盒:" + boxRequest.getData().getDeviceId() + ",流水号:" + boxRequest.getData().getTransacSeq(),
				JSON.toJSONString(boxRequest)));

		Send2AppThread appThread = new Send2AppThread(itcsApp, channelHandlerContext, boxRequest);
		executorService.execute(appThread);
	}

}
